package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.User.Dao.User;
import com.function.Function;

/**
 * Servlet implementation class ServletRegir
 */
@WebServlet("/ServletRegir")
public class ServletRegir extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		String sno = request.getParameter("sno");
		String paw = request.getParameter("password");
		String srepaw = request.getParameter("srepaw");
		try {
			User users = new User(sno, paw, userName, srepaw);
			if(Function.insertInfo(users)){
				request.setAttribute("userSno", sno);
				request.getRequestDispatcher("Main.jsp").forward(request, response);
			}else {
				request.setAttribute("error", "error");
				request.getRequestDispatcher("regir.jsp").forward(request, response);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
